
import { GraphNode } from "@/js/components/GraphNode"
import { GraphView } from "@/js/components/GraphView"
import { InputLinkNodeAny, InputLinkNodeBoolean, InputLinkNodeColor, InputLinkNodeFlow, InputLinkNodeFunction, InputLinkNodeGroup, InputLinkNodeNumber, InputLinkNodeObject, InputLinkNodeString } from "@/js/components/InputLinkNode"

export class ClassMethod extends GraphNode{
    group?: InputLinkNodeGroup
    load(){
        super.load()

        const layout = new this.DefaultLayout(this, this.graphView as GraphView, true, false)
        this.layout = layout
        this.appendChild(layout.container)

        layout.main?.right.appendChild(new InputLinkNodeFlow(this, this.graphView as GraphView, {
            name: "body", 
            desc: '方法体',
            model: "output",
            showInput: false,
        }))

        const group = new InputLinkNodeGroup( this, this.graphView as GraphView , {
            name: 'arguments'
        })
        layout.main?.right.appendChild(group)
        group.addInputLinkNode("字符串(string)", InputLinkNodeString, {
            name: '',
            desc: '字符串(string)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            inputValue: '',
            isBindValue: false
        }).addInputLinkNode("数值(number)", InputLinkNodeNumber, {
            name: '',
            desc: '数值(number)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("布尔(boolean)", InputLinkNodeBoolean, {
            name: '',
            desc: '布尔(boolean)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("对象(object)", InputLinkNodeObject, {
            name: '',
            desc: '对象(object)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("函数(function)", InputLinkNodeFunction, {
            name: '',
            desc: '函数(function)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("通用(any)", InputLinkNodeAny, {
            name: '',
            desc: '通用(any)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        })
        .layout?.alignItems('flex-end')
        this.group = group
    }

    import(obj:any){
        this.group?.import(obj.userData.arguments)
        super.import(obj)
    }
}

ClassMethod.parser = ({node,toNode, regExpHelper}: any)=>{
    const next = toNode(node.outputs.body[0], 'enter')
    
    // const methods = node.userData.methods || [] // 获取自定义的方法信息

    // // 方法在 outputs 里面 
    // let methodCode = '' 
    // methods.map((item:any)=>{
    //     const linkNodeInfo = node.outputs[item.uuid] // 获取链接信息
    //     const methodName = item.data

    //     if(regExpHelper.isValidVariableName(methodName)){
    //         const body = toNode(linkNodeInfo[0], 'output', null) 
    //         if(body){
    //             methodCode += `${methodName}(){${body};}`
    //         }
    //         else new Error(`未定义类${className} 的 ${methodName} 方法的方法体`)
    //     }
    //     else{
    //         throw new Error(`"${methodName}" 不符合类${className}方法命名规范,  或未进行方法命名`)
    //     }
    // })
    
    return `(){${next}}`
}
